package com.jw.xzg.activity;

import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.jw.xzg.R;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {
    Dialog startDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);

        onStartClick();

    }


    public void onStartClick(){
        startDialog=  new Dialog(SplashActivity.this);
        startDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        startDialog.setContentView(R.layout.dialog_splash);

        // dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        startDialog.getWindow().setBackgroundDrawable(new ColorDrawable());
        startDialog.setCancelable(false);

        startDialog.show();



        final Intent loginIntent=new Intent(this,LoginActivity.class);

        SharedPreferences sp = getSharedPreferences("userInfo", 0);
         boolean isFirst =sp.getBoolean("isFirst", false);
        if(!isFirst){
            final Intent intent=new Intent(this,VideoActivity.class);
            Timer timer=new Timer();
            TimerTask task=new TimerTask()
            {
                @Override
                public void run(){
                    startActivity(intent);
                    //MainActivity.this.finish();
                }
            };
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("isFirst",true);
            editor.commit();
            timer.schedule(task,3000);
        }else{
            Timer timer=new Timer();
            TimerTask task=new TimerTask()
            {
                @Override
                public void run(){
                    //final Intent intent=new Intent(this,LoginActivity.class);
                    startActivity(loginIntent);
                }
            };
            timer.schedule(task,3000);

        }


    }

}
